package View.LinearFilterTable;

import Model.LinearFilter;

import javax.swing.table.AbstractTableModel;

/**
 * Created by IntelliJ IDEA.
 * User: Andrew
 * Date: 09.03.12
 * Time: 21:41
 * To change this template use File | Settings | File Templates.
 */
public class LinearFilterTableModel extends AbstractTableModel {
   // private String[] colNames = {"�", "�������", "���", "��������", "��������� �������"};
    private final int colNum = 5;
    private LinearFilter rowData;
    //private TreeMap<Integer, Federal> federalMap;

    /*public ArrayList<Federal> getRowData() {
        return rowData;
    }   */

    public void setRowData(LinearFilter rowData) {
        this.rowData = rowData;
    }
    
    public void setRowDataAt(float x, int r, int c)
    {
        if (rowData.getSize() == 5) {
            rowData.getData()[r * 5 + c] = x;
        }
        if (rowData.getSize() == 3) {
            rowData.getData()[(r-1) * 3 + c - 1] = x;
        }
        fireTableDataChanged();
    }

    public LinearFilter getRowData() {
        return rowData;
    }

    public LinearFilterTableModel()
    {
        super();
    }

    public int getRowCount() {
        return colNum;
    }

    public int getColumnCount() {
        return colNum;
    }
    /*public String getColumnName(int c)
    {
        return colNames[c];
    } */
    public Object getValueAt(int r, int c)
    {
        if (rowData.getSize() == 5) {
            return rowData.getData()[r * colNum + c];
        }
        if (rowData.getSize() == 3) {
            if (r == 0 || r == 4 || c == 0 || c == 4) {
                return null;
            } else {
                return rowData.getData()[(r-1) * 3 + c -1];
            }
        }
        return null;
    }
    public Class getColumnClass(int c)
    {
        return Float.class;
        /*
        switch (c)
        {
            case 0 :
            case 4 :
                return Integer.class;
            case 1 :
            case 2 :
            case 3 :
                return String.class;
        }
        return null;  */
    }

    public boolean isCellEditable(int rowIndex, int columnIndex)
    {
        if (rowData.getSize() == 5) {
            return true;
        }
        if (rowData.getSize() == 3) {
            if (rowIndex == 0 || rowIndex == 4 || columnIndex == 0 || columnIndex == 4) {
                return false;
            } else {
                return true;
            }
        }
        return false;
    }

}